'use strict';

module.exports = app => {
  const { STRING, INTEGER, DATE, DECIMAL } = app.Sequelize;

  const Reservation = app.model.define('reservation', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    memberId: { type: INTEGER, allowNull: false, comment: '会员ID' },
    foodId: { type: INTEGER, allowNull: false, comment: '美食ID' },
    reserveDate: { type: DATE, allowNull: false, comment: '预定日期' },
    reserveTime: { type: STRING(20), allowNull: false, comment: '预定时间段' },
    personCount: { type: INTEGER, allowNull: false, comment: '就餐人数' },
    amount: { type: DECIMAL(10, 2), allowNull: false, comment: '订单金额' },
    remark: { type: STRING(255), comment: '备注' },
    status: { type: INTEGER, defaultValue: 1, comment: '状态：1-待确认，2-已确认，3-已完成，0-已取消' },
    createdAt: DATE,
    updatedAt: DATE,
  });

  Reservation.associate = function() {
    app.model.Reservation.belongsTo(app.model.Member, { foreignKey: 'memberId', as: 'member' });
    app.model.Reservation.belongsTo(app.model.Food, { foreignKey: 'foodId', as: 'food' });
  };

  return Reservation;
};
